import React from 'react';
import PropTypes from 'prop-types';
import { Modal } from 'antd';
import BaseForm from './form';

class FormModal extends React.Component {
	handleOk = () => {
		const { onOk } = this.props;
		this.form.validateFields((errors) => {
			if (errors) {
				return;
			}
			console.log(this.form.getValue());
			console.log(this.form.getFieldsValue());
      onOk(this.form.getValue());
		});
	};

	render() {
		const { item = {}, roles, products, app, ...modalProps } = this.props;

		const modalOpts = {
			...modalProps,
			onOk: this.handleOk,
		};
		return (
			<Modal {...modalOpts} width={950}>
				<BaseForm
					app={app}
					item={item}
					roles={roles}
          products={products}
					ref={d => d ? this.form = d : null}
				/>
			</Modal>
		);
	}
}

FormModal.propTypes = {
	form: PropTypes.object.isRequired,
	type: PropTypes.string,
	item: PropTypes.object,
	onOk: PropTypes.func,
};

export default FormModal;
